import yaml
import os

# 追加写入
def write_yaml(filename,data):
    with open(os.getcwd()+"/data/"+filename,encoding="utf-8",mode="a+") as f:
        yaml.safe_dump(data,stream=f,allow_unicode=True)

# 读取
def read_yaml(filename,key):
    with open(os.getcwd()+"/data/"+filename,encoding="utf-8",mode="r") as f:
        # yaml.safe_load:将yaml中的映射转为python的字典
        data=yaml.safe_load(f)
        return data[key]

# 清空
def clear_yaml(filename):
    with open(os.getcwd()+"/data/"+filename,encoding="utf-8",mode="w") as f:
        f.truncate()

# if __name__=="__main__":
#     print(os.getcwd())
#     # D:\测试开发学习 - gitee\test - development - learning\apiautotest_blog\utils